<%@page import="interfaces.DALException"%>
<%@page import="java.util.List"%>
<%@page import="dto_objects.*"%>
<%@page import="java.util.ArrayList"%>
<%@page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>

<% 
String login = "<form action=\"LoginServlet\">"+
		"Username:<br>"+
		"<input type=\"text\" name=\"un\"><br>"+
		"Password:<br>"+
		"<input type=\"text\" name=\"pw\">"+
		"<input type=\"submit\" value=\"log In\">"+
		"&nbsp;"+
		"</form>";
%>

<script type="text/javascript" src="../javascripts/jquery-latest.pack.js"></script>
<script type="text/javascript" src="../javascripts/popup.js"></script>

<jsp:useBean id="func" class="Function.FunctionWEB" scope="session"/>  

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
	<title>Main Page</title>
	<link rel="stylesheet" type="text/css" href="../NewStyle.css">
</head>
<body>
	<div id=topBox>
			<div id=searchField>
				<form action="../Web/MainPage.jsp">
				<input type="text" name="searchText"> 
				<input type="submit" value="">
				<a id="aSearchButton" href="aSearch.jsp">Advanced search</a>
				</form>			
			</div>
	
			<div id=login>
				<%out.print(func.getClass().getName());
				if(session.getAttribute("currentSessionUser") == null){
					session.setAttribute("userMENU", null);
					out.print("<a class=myButton href=\"#loginField\" name=\"loginFieldClick\">Login</a>");
				}else{
					out.print("<form action=\"../LoginServlet\">"+
							"<input class=myButton type=\"submit\" value=\"Log Out\" name=\"logout\">"+
							"</form>");
				}
				%>
				
				
			</div>
	</div>
	<div id=main>
		<div id=header>

		</div>
		<div id=content>
			<div id=data>

<form method="GET">
<div class=tabledesign style="float:left;">
	<%
	
	out.print("<table id=\"tabledesign\">");
	out.print("<tr>");
	out.print("<td>Book Name </td>");
	out.print("<td>First Name </td>");
	out.print("<td>Last Name  </td>");
	out.print("<td>Subject </td>");
	out.print("<td>Publisher </td>");
	out.print("</tr>");
		out.print("<tr>");
		out.print("<td><input type=\"text\" name=\"book\" value=\"\" size=10></td>"); 
		out.print("<td><input type=\"text\" name=\"author_first\" value=\"\" size=10></td>"); 
		out.print("<td><input type=\"text\" name=\"author_last\" value=\"\" size=10></td>"); 
		out.print("<td><input type=\"text\" name=\"subject\" value=\"\" size=7></td>"); 
		out.print("<td><input type=\"text\" name=\"publisher\" value=\"\" size=7></td>");
		out.print("</tr>");
	out.print("</table>");
%>
</div>
<br><input type="submit" name="action" value="Search">
<div id=data>
<%


if (request.getMethod().equals("GET") && request.getParameter("book") != null){
	if(request.getParameter("action").equalsIgnoreCase("Search")){
		String bookname = request.getParameter("book");
		String authorFirstName = request.getParameter("author_first");
		String authorLastName = request.getParameter("author_last");
		String subject = request.getParameter("subject");
		String publisher = request.getParameter("publisher");
		List<BookDTO> searchList = func.advancedSearch(bookname, authorFirstName, authorLastName, subject, publisher);
		for(int x=0;x<=searchList.size();x++){
			try{
			out.print(searchList.get(x).getTitle()+"<br>");
			for(int y=0;y<searchList.get(x).getAuthors().size();y++){
				out.print(searchList.get(x).getAuthors().get(y).getAuthorFirstName()+" ");
				out.print(searchList.get(x).getAuthors().get(y).getAuthorLastName()+"<br>");
				}
			for(int z=0;z<searchList.get(x).getSubjects().size();z++){
			out.print(searchList.get(x).getSubjects().get(z).getSubject_name()+"<br>");
			}
			out.print(searchList.get(x).getPublisher().getPublisher_name()+"<br>"+"<br>");
			}catch(IndexOutOfBoundsException e){
				
			}
		}
		
	}
}



%>
</div>
</form>		
		
			</div>
		${userMENU}
		</div>
	</div>

<div id="loginField" class="window">
	<form action="../LoginServlet">
			Username:
			<input type="text" name="un"><br>
			Password:
			<input type="text" name="pw"><br>
			<input type="submit" value="Log In">
		</form>	
		<br>
	<a href="#"class="close" align=right style="color: #333;text-align: right;text-decoration: none;">Close</a>
</div>	
<div id="mask"></div>

</body>
</html>